package tsj.ai.alibaba.data.analysis.node;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.action.NodeAction;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tsj.ai.alibaba.data.analysis.prompt.PromptHelper;
import tsj.ai.alibaba.data.analysis.service.llm.BlockLlmService;

import java.util.HashMap;
import java.util.Map;

import static tsj.ai.alibaba.data.analysis.constant.Constant.*;

/**
 * @author taoshujian
 * @version 1.0
 * @since 2025-11-13 08:59:59
 */
@Slf4j
@Component
public class QueryRewriteNode implements NodeAction {

    @Autowired
    private BlockLlmService blockLlmService;

    @Override
    public Map<String, Object> apply(OverAllState state) throws Exception {
        String query = state.value(INPUT_KEY, "");

        // 使用统一管理的提示词构建时间转换提示
        String timeConversionPrompt = PromptHelper.buildTimeConversionPrompt(query);
        String queryWithTime = blockLlmService.chat(timeConversionPrompt);

        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put(QUERY_REWRITE_NODE_OUTPUT, queryWithTime);
        return resultMap;
    }
}
